package com.example.mes_boot.controller;

import com.example.mes_boot.pojo.checkpoint;
import com.example.mes_boot.service.Indexservice;
import com.example.mes_boot.service.imp.addservieimpl;
import com.example.mes_boot.service.imp.updataservieimpl;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mes_boot.service.imp.deleservieimpl;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/index")
public class indexcontroller {
    @Autowired
    private Indexservice indexservice;
    //加载接口
    @PostMapping("/load")
    private List<checkpoint> find(){
       return indexservice.findBy();
    }
    //分页接口
    @PostMapping("/page")
    private List<checkpoint> findby(@RequestBody checkpoint point) {
        int currPage=point.getPage();//当前页码
        int pageSize=8;//当前页显示记录数量
        //注意：currPage和start别搞错了，一个表示当前页码，一个是从第几行读取记录
        int start = (currPage-1)*pageSize;//计算从第几行读取记录
        RowBounds rowBounds = new RowBounds(start,pageSize);
        System.out.println(rowBounds);
        return indexservice.findBypage(rowBounds);
    }
    //查询接口
    @PostMapping("/sele")
    private List<checkpoint> findBysele(@RequestBody checkpoint checkpoint){
        int currPage=1  ;//当前页码
        int pageSize=8;//当前页显示记录数量
        //注意：currPage和start别搞错了，一个表示当前页码，一个是从第几行读取记录
        int start = (currPage-1)*pageSize;//计算从第几行读取记录
        RowBounds rowBounds = new RowBounds(start,pageSize);
        System.out.println(checkpoint);
        return indexservice.findBysele( rowBounds,checkpoint.getName(),checkpoint.getAddress(),checkpoint.getStatus());
    }
    //删除接口
    @Autowired
    private  deleservieimpl deleservieimpl;
    @PostMapping("/dele")
    private void dele(@RequestBody checkpoint oid ){
        System.out.println(oid.getId());
        deleservieimpl.dele(oid.getId());
    }
    //修改节点
    @Autowired
    private updataservieimpl updataservieimpl;
    @PostMapping("/updata")
    private void  updata(@RequestBody checkpoint upda){
        System.out.println(upda);
            updataservieimpl.updata(upda.getId(),upda.getName(),upda.getAddress(),
                    upda.getRt_power(),upda.getRt_voltage(),upda.getStatus(),upda.getRemark());
    }
    //新增节点
    @Autowired
    private addservieimpl addservieimpl;
    @PostMapping("/add")
    private  void  add(@RequestBody checkpoint add){
        addservieimpl.add(add.getName(),add.getAddress(),
                add.getRt_power(),add.getRt_voltage(),add.getStatus(),add.getRemark());
    }
}
